﻿//    ORMAC
//    A micro-ORM for .NET
//    Copyright (C) <2012>  <A.Ghomi>

//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.

//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.

//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ORMAC.Attributes;
using ORMAC;

namespace SimpleClass1
{
    /// <summary>
    /// This is a poco class decorated with ORMAC attributes
    /// </summary>
    //Use "Table" attribute to specify the database table name for this class
    [Table("Customers")]
    public class OCustomers
    {
        /// <summary>
        /// Use primary key attribute to specify primary key column name
        /// </summary>
        [PrimaryKey]
        [Field("CustomerID")]
        public string CustomerID
        {
            get;
            set;
        }
        /// <summary>
        /// Use "Field" attribute to specify the database column name for this property
        /// </summary>
        [Field("CompanyName")]
        public string CompanyName
        {
            get;
            set;
        }
        [Field("ContactName")]
        public string ContactName
        {
            get;
            set;
        }
        [Field("Phone")]
        public string Phone
        {
            get;
            set;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is an ORMAC test application. It will try to connect to Nothrthwind database and list the customers:");
            //Create the ORMAC reader object
            IReader reader = new OReader();
            //set the connection string
            reader.SetConnectionString("Data Source=localhost;Initial Catalog=Northwind;Integrated Security=True");
            try{
                //load the object list from the database
                var customers=reader.LoadFromDatabase<OCustomers>();
                foreach (var c in customers)
                {
                    Console.WriteLine(string.Format("Contact Name:{0} Tel:{1}",c.ContactName,c.Phone));
                }
            }catch(Exception ex){
                Console.WriteLine(ex.Message);            
            }
            Console.WriteLine("Press any key to terminate");
            Console.ReadKey();
        }
    }
}
